﻿using System;
using System.Net.Http;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace EurekaService.Business
{
    public interface IService
    {
        Task<string> GetValue(string serviceName);
    }

    public class Service : IService
    {
        ILogger<Service> _logger;
        private readonly HttpClient _httpClient;

        public Service(ILoggerFactory logFactory, HttpClient httpClient)
        {
            _logger = logFactory.CreateLogger<Service>(); ;
            _httpClient = httpClient;
        }

        public async Task<string> GetValue(string serviceName)
        {
            try
            {
                return await _httpClient.GetStringAsync(serviceName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

        }
    }
}